﻿Public Class frmInThongKeXuatKho
    'ReportType 1- ngày; 2- tháng; 3-năm; 4-từ ngày đến ngày
    Public ReportType As Integer
    Public Ngay As String
    Public Thang As String
    Public Nam As String

    Public TuNgay As String
    Public DenNgay As String
    Public sTuNgay As String
    Public sDenNgay As String
    Public dtThongKeNhapKho As DataTable
    Public SoHoDon As String

    Private Sub frmInThongKeXuatKho_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.WindowState = FormWindowState.Maximized
        Select Case ReportType
            Case 0
                Report_TheoNgay()
            Case 1
                Report_TheoThang()
            Case 2
                Report_TheoNam()
            Case 3
                Report_TuNgayDenNgay()
            Case 4
                Report_TheoSoPhieu()
        End Select
    End Sub
#Region "Thông kê xuất kho"
    Private TongXuat As Single = 0
    Public Sub Report_TheoSoPhieu()
        Try
            dtThongKeNhapKho.Columns.Add("Ngay")
            For Each dr As DataRow In dtThongKeNhapKho.Rows
                dr.Item("Ngay") = dr.Item("NgayNhapKho")
            Next
            Dim objReport As New rptChiTietXuat
            objReport.Database.Tables("dtXuatKho").SetDataSource(dtThongKeNhapKho)
            'title report
            Dim dtTitle As New DataTable
            dtTitle.Columns.Add("Title")
            Dim newRow As DataRow
            newRow = dtTitle.NewRow
            newRow("Title") = "Số hóa đơn " & SoHoDon
            dtTitle.Rows.Add(newRow)
            dtTitle.AcceptChanges()
            objReport.Database.Tables("dtTitleReport").SetDataSource(dtTitle)
            cvrThongKe.ReportSource = objReport
        Catch ex As Exception
            ShowError()
        End Try
    End Sub
    Public Sub Report_TheoNgay()
        Try
            'Dim dbConn As New OleDb.OleDbConnection
            'Dim dataAccess As New DataAccess
            'Dim dtThongKeNhapKho As New DataTable
            'Dim query As String
            'query = "Select DH.NgayBan As Ngay,SP.MaSanPham As MaSo,SP.TenSanPham As TenGoi,CT.SoLuong AS SoLuong,DH.TenKhachHang As DienGiai" & _
            '        " From DonHangBan as DH" & _
            '        " Left Outer Join ChiTietDonHangBan As CT On DH.IdDonHangBan = CT.IDDonHangBan" & _
            '        " Left Outer Join SanPham As SP On Sp.IDSanPham = CT.IDSanPham" & _
            '        " Where CT.Xoa=0 And DH.Xoa=0 And CT.LoaiPhi = N'HangHoa' And CT.TrangThai=N'Đã duyệt' And Ngay='" & Ngay & "'"
            'Dim adapter As OleDb.OleDbDataAdapter
            'dataAccess.ConnectDatabase_DBAccess(dbConn)
            'adapter = New OleDb.OleDbDataAdapter(query, dbConn)
            'adapter.Fill(dtThongKeNhapKho)
            'dbConn.Close()
            'For i As Integer = 0 To dtThongKeNhapKho.Rows.Count - 1
            '    formatDate2VN(dtThongKeNhapKho.Rows(i)("Ngay"))
            '    TongXuat = TongXuat + Single.Parse(dtThongKeNhapKho.Rows(i)("SoLuong").ToString)
            'Next
            'dbConn.Close()
            dtThongKeNhapKho.Columns.Add("Ngay")
            For Each dr As DataRow In dtThongKeNhapKho.Rows
                dr.Item("Ngay") = dr.Item("NgayNhapKho")
            Next
            Dim objReport As New rptChiTietXuat
            objReport.Database.Tables("dtXuatKho").SetDataSource(dtThongKeNhapKho)
            'title report
            Dim dtTitle As New DataTable
            dtTitle.Columns.Add("Title")
            Dim newRow As DataRow
            newRow = dtTitle.NewRow
            formatDate2VN(Ngay)
            newRow("Title") = "Ngày " & Ngay
            dtTitle.Rows.Add(newRow)
            dtTitle.AcceptChanges()
            objReport.Database.Tables("dtTitleReport").SetDataSource(dtTitle)
            cvrThongKe.ReportSource = objReport
        Catch ex As Exception
            ShowError()
        End Try
    End Sub
    Public Sub Report_TheoThang()
        Try
            'Dim dbConn As New OleDb.OleDbConnection
            'Dim dataAccess As New DataAccess
            'Dim dtThongKeNhapKho As New DataTable
            'Dim query As String
            'query = "Select DH.NgayBan As Ngay,SP.MaSanPham As MaSo,SP.TenSanPham As TenGoi,CT.SoLuong AS SoLuong,DH.TenKhachHang As DienGiai" & _
            '        " From DonHangBan as DH" & _
            '        " Left Outer Join ChiTietDonHangBan As CT On DH.IdDonHangBan = CT.IDDonHangBan" & _
            '        " Left Outer Join SanPham As SP On Sp.IDSanPham = CT.IDSanPham" & _
            '        " Where CT.Xoa=0 And DH.Xoa=0 And CT.LoaiPhi = N'HangHoa' And CT.TrangThai=N'Đã duyệt' And CT.Thang='" & Thang & "'"
            'Dim adapter As OleDb.OleDbDataAdapter
            'dataAccess.ConnectDatabase_DBAccess(dbConn)
            'adapter = New OleDb.OleDbDataAdapter(query, dbConn)
            'adapter.Fill(dtThongKeNhapKho)
            'dbConn.Close()
            'For i As Integer = 0 To dtThongKeNhapKho.Rows.Count - 1
            '    formatDate2VN(dtThongKeNhapKho.Rows(i)("Ngay"))
            '    TongXuat = TongXuat + Single.Parse(dtThongKeNhapKho.Rows(i)("SoLuong").ToString)
            'Next
            'dbConn.Close()
            Dim objReport As New rptChiTietXuat
            dtThongKeNhapKho.Columns.Add("Ngay")
            For Each dr As DataRow In dtThongKeNhapKho.Rows
                dr.Item("Ngay") = dr.Item("NgayNhapKho")
            Next
            objReport.Database.Tables("dtXuatKho").SetDataSource(dtThongKeNhapKho)
            'title report
            Dim dtTitle As New DataTable
            dtTitle.Columns.Add("Title")
            Dim newRow As DataRow
            newRow = dtTitle.NewRow
            newRow("Title") = "Tháng " & Thang
            dtTitle.Rows.Add(newRow)
            dtTitle.AcceptChanges()
            objReport.Database.Tables("dtTitleReport").SetDataSource(dtTitle)
            cvrThongKe.ReportSource = objReport
        Catch ex As Exception
            ShowError()
        End Try
    End Sub
    Public Sub Report_TheoNam()
        Try
            'Dim dbConn As New OleDb.OleDbConnection
            'Dim dataAccess As New DataAccess
            'Dim dtThongKeNhapKho As New DataTable
            'Dim query As String
            'query = "Select DH.NgayBan As Ngay,SP.MaSanPham As MaSo,SP.TenSanPham As TenGoi,CT.SoLuong AS SoLuong,DH.TenKhachHang As DienGiai" & _
            '        " From DonHangBan as DH" & _
            '        " Left Outer Join ChiTietDonHangBan As CT On DH.IdDonHangBan = CT.IDDonHangBan" & _
            '        " Left Outer Join SanPham As SP On Sp.IDSanPham = CT.IDSanPham" & _
            '        " Where CT.Xoa=0 And DH.Xoa=0 And CT.LoaiPhi = N'HangHoa' And CT.TrangThai=N'Đã duyệt' And CT.Nam='" & Nam & "'"
            'Dim adapter As OleDb.OleDbDataAdapter
            'dataAccess.ConnectDatabase_DBAccess(dbConn)
            'adapter = New OleDb.OleDbDataAdapter(query, dbConn)
            'adapter.Fill(dtThongKeNhapKho)
            'dbConn.Close()
            'For i As Integer = 0 To dtThongKeNhapKho.Rows.Count - 1
            '    formatDate2VN(dtThongKeNhapKho.Rows(i)("Ngay"))
            '    TongXuat = TongXuat + Single.Parse(dtThongKeNhapKho.Rows(i)("SoLuong").ToString)
            'Next
            'dbConn.Close()
            Dim objReport As New rptChiTietXuat
            dtThongKeNhapKho.Columns.Add("Ngay")
            For Each dr As DataRow In dtThongKeNhapKho.Rows
                dr.Item("Ngay") = dr.Item("NgayNhapKho")
            Next
            objReport.Database.Tables("dtXuatKho").SetDataSource(dtThongKeNhapKho)
            'title report
            Dim dtTitle As New DataTable
            dtTitle.Columns.Add("Title")
            Dim newRow As DataRow
            newRow = dtTitle.NewRow
            newRow("Title") = "Năm " & Nam
            dtTitle.Rows.Add(newRow)
            dtTitle.AcceptChanges()
            objReport.Database.Tables("dtTitleReport").SetDataSource(dtTitle)
            cvrThongKe.ReportSource = objReport
        Catch ex As Exception
            ShowError()
        End Try
    End Sub
    Public Sub Report_TuNgayDenNgay()
        Try
            'Dim dbConn As New OleDb.OleDbConnection
            'Dim dataAccess As New DataAccess
            'Dim dtThongKeNhapKho As New DataTable
            'Dim query As String
            'query = "Select DH.NgayBan As Ngay,SP.MaSanPham As MaSo,SP.TenSanPham As TenGoi,CT.SoLuong AS SoLuong,DH.TenKhachHang As DienGiai" & _
            '        " From DonHangBan as DH" & _
            '        " Left Outer Join ChiTietDonHangBan As CT On DH.IdDonHangBan = CT.IDDonHangBan" & _
            '        " Left Outer Join SanPham As SP On Sp.IDSanPham = CT.IDSanPham" & _
            '        " Where CT.Xoa=0 And DH.Xoa=0 And CT.LoaiPhi = N'HangHoa' And CT.TrangThai=N'Đã duyệt' And CT.Ngay_So <=" & DenNgay & " And CT.Ngay_So >=" & TuNgay & ""
            'Dim adapter As OleDb.OleDbDataAdapter
            'dataAccess.ConnectDatabase_DBAccess(dbConn)
            'adapter = New OleDb.OleDbDataAdapter(query, dbConn)
            'adapter.Fill(dtThongKeNhapKho)
            'dbConn.Close()
            'For i As Integer = 0 To dtThongKeNhapKho.Rows.Count - 1
            '    formatDate2VN(dtThongKeNhapKho.Rows(i)("Ngay"))
            '    TongXuat = TongXuat + Single.Parse(dtThongKeNhapKho.Rows(i)("SoLuong").ToString)
            'Next
            'dbConn.Close()
            Dim objReport As New rptChiTietXuat
            dtThongKeNhapKho.Columns.Add("Ngay")
            For Each dr As DataRow In dtThongKeNhapKho.Rows
                dr.Item("Ngay") = dr.Item("NgayNhapKho")
            Next
            objReport.Database.Tables("dtXuatKho").SetDataSource(dtThongKeNhapKho)
            'title report
            Dim dtTitle As New DataTable
            dtTitle.Columns.Add("Title")
            Dim newRow As DataRow
            newRow = dtTitle.NewRow
            newRow("Title") = "Từ ngày " & sTuNgay & " Đến ngày " & sDenNgay
            dtTitle.Rows.Add(newRow)
            dtTitle.AcceptChanges()
            objReport.Database.Tables("dtTitleReport").SetDataSource(dtTitle)
            cvrThongKe.ReportSource = objReport
        Catch ex As Exception
            ShowError()
        End Try
    End Sub
#End Region

End Class